﻿package frEngine.shader.filters.fragmentFilters
{
    import __AS3__.vec.*;
    import baseEngine.core.*;
    import frEngine.shader.*;
    import frEngine.shader.filters.*;
    import frEngine.shader.registType.*;

    public class SpaceWarpFilter extends FilterBase
    {
        public var warpConst:Vector.<Number>;

        public function SpaceWarpFilter()
        {
            this.warpConst = this.Vector.<Number>([0.015, 0.03, 0, 0]);
            super(FilterType.SpaceWarp, FilterPriority.SpaceWarpFilter);
            return;
        }// end function

        override public function setRegisterParams(param1:Program3dRegisterInstance) : void
        {
            param1.getParamByName("{warpConst}", false).value = this.warpConst;
            return;
        }// end function

        override public function get programeId() : String
        {
            return "SpaceWarpFilter0";
        }// end function

        override public function createFragmentUvCoord(param1:Program3dRegisterInstance) : String
        {
            var _loc_4:Array = null;
            var _loc_5:FsParam = null;
            var _loc_6:Texture3D = null;
            var _loc_7:String = null;
            var _loc_2:String = "";
            var _loc_3:* = param1.getParamByName(FilterName.F_UVPostion, false);
            if (_loc_3)
            {
                _loc_4 = new Array();
                _loc_4.push(new ToBuilderInfo("fc0", "{warpConst}", false, 1, this.warpConst));
                _loc_5 = param1.getParamByName("{texture2}", false);
                _loc_6 = _loc_5.value;
                _loc_7 = getSmapleString("{texture2}", _loc_6.format, true, _loc_6.mipMode);
                _loc_2 = _loc_2 + ("tex \t\tft1, \t\t\t{F_UVPostion}, " + _loc_7 + "\n");
                _loc_2 = _loc_2 + "mov \t\tft2, \t\t\tft1\t\t\t\t\t\t\t\t\n";
                _loc_2 = _loc_2 + "dp3 \t\tft3.x, \t\tft2.xyz ,   \t{fcConst1}.z\t\t\t\n";
                _loc_2 = _loc_2 + "sne      ft3.x,       ft3.x,              {fcConst1}.x  \n";
                _loc_2 = _loc_2 + "sub      ft2.xyz,          ft2.xyz,           {fcConst1}.w  \n";
                _loc_2 = _loc_2 + "mov      ft2.z,                  {fcConst1}.x  \n";
                _loc_2 = _loc_2 + "nrm \t\tft2.xyz, \t\tft2.xyz \t\t\t\t\t\t\n";
                _loc_2 = _loc_2 + "mul      ft2.xyz,         ft2.xyz ,        ft3.x \n";
                _loc_2 = _loc_2 + "mul \t\tft2, \t\t\tft2, \t\t\t \t\tft1.w \t\n";
                _loc_2 = _loc_2 + "mul \t\tft2, \t\t\tft2,  \t\t\t\t\tfc0 \t\n";
                _loc_2 = _loc_2 + "add \t\t{F_UVPostion},{F_UVPostion}, \t\tft2 \t\n";
                _loc_2 = param1.toBuild(_loc_2, _loc_4);
            }
            return _loc_2;
        }// end function

    }
}
